package com.mysoft.gfyx.workbench.controller;

import com.mysoft.framework.rpc.annotation.PubAction;
import com.mysoft.framework.rpc.annotation.PubService;
import com.mysoft.framework.rpc.contants.RequestPrefix;
import com.mysoft.framework.sdk.system.dto.ActionRightInfoDTO;
import com.mysoft.gfyx.common.util.PermUtil;
import com.mysoft.gfyx.workbench.controller.dto.NavWidgetAttrDto;
import com.mysoft.gfyx.workbench.controller.dto.QuotaNewResponseDto;
import com.mysoft.gfyx.workbench.controller.dto.QuotaResponseDto;
import com.mysoft.gfyx.workbench.remoteservice.RemoteStatisticService;
import com.mysoft.gfyx.workbench.service.ProfitService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@PubService(value = "/statisticsDataApi", prefix = RequestPrefix.API)
@Tag(name = "指标控制器-API")
public class StatisticsDataApiController {

    @Resource
    private RemoteStatisticService remoteStatisticService;

    @Autowired
    private PermUtil permUtil;

    @PubAction(value = "/quota", method = RequestMethod.POST)
    public QuotaNewResponseDto myQuota() throws Exception {
        // [{"key":"myClue", "name":"我的线索", "value": 6,"is_enable": 1}]
        QuotaNewResponseDto quotaNewResponseDto = new QuotaNewResponseDto();
        QuotaResponseDto data = remoteStatisticService.quota();

        boolean enableMarketingPerm = permUtil.checkBusinessUnit(permUtil.marketActionCode);
        boolean enableCluePerm = permUtil.checkBusinessUnit(permUtil.clueActionCode);

        // 我的线索
        NavWidgetAttrDto navMyClueDto = new NavWidgetAttrDto();
        navMyClueDto.setKey("myClue");
        navMyClueDto.setName("我的线索");
        navMyClueDto.setNum(data.getMyClue());
        if ((enableCluePerm)) {
            navMyClueDto.setDisable(0);
        } else {
            navMyClueDto.setDisable(1);
        }

        // 我的客户
        NavWidgetAttrDto navMyCustomerDto = new NavWidgetAttrDto();
        navMyCustomerDto.setKey("myCustomer");
        navMyCustomerDto.setName("我的客户");
        navMyCustomerDto.setNum(data.getMyCustomer());
        if ((enableMarketingPerm)) {
            navMyCustomerDto.setDisable(0);
        } else {
            navMyCustomerDto.setDisable(1);
        }

        // 我的订阅
        NavWidgetAttrDto navMySubscribeNewsDto = new NavWidgetAttrDto();
        navMySubscribeNewsDto.setKey("mySubscribeNews");
        navMySubscribeNewsDto.setName("我的订阅");
        navMySubscribeNewsDto.setNum(data.getMySubscribeNews());
        if ((enableCluePerm)) {
            navMySubscribeNewsDto.setDisable(0);
        } else {
            navMySubscribeNewsDto.setDisable(1);
        }

        // 客户动态
        NavWidgetAttrDto navMySubscribeItemsDto = new NavWidgetAttrDto();
        navMySubscribeItemsDto.setKey("myClue");
        navMySubscribeItemsDto.setName("客户动态");
        navMySubscribeItemsDto.setNum(data.getMySubscribeItems());
        if ((enableMarketingPerm)) {
            navMySubscribeItemsDto.setDisable(0);
        } else {
            navMySubscribeItemsDto.setDisable(1);
        }

        quotaNewResponseDto.setMyClue(navMyClueDto);
        quotaNewResponseDto.setMyCustomer(navMyCustomerDto);
        quotaNewResponseDto.setMySubscribeNews(navMySubscribeNewsDto);
        quotaNewResponseDto.setMySubscribeItems(navMySubscribeItemsDto);

        return quotaNewResponseDto;
    }


}
